import React from "react";
import axios from "axios";
const apiUrl = process.env.REACT_APP_API_URL;
export const Login = () => {
  interface Ilogin {
    username: string;
    password: string;
  }
  const login = (params: Ilogin) => {
    axios.post(`${apiUrl}/login`, params).then((res) => {
      console.log(res);
      if (res.status === 200) {
        console.log("888");
      }
    });
  };

  const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
    event.preventDefault();
    const username = (event.currentTarget.elements[0] as HTMLInputElement)
      .value;
    const password = (event.currentTarget.elements[1] as HTMLInputElement)
      .value;
    login({ username, password });
  };
  return (
    <div className="login">
      <form onSubmit={handleSubmit}>
        <label htmlFor="username">用户名</label>
        <input type="text" id={"username"} />
        <label htmlFor="password">密码</label>
        <input type="text" id={"password"} />
        <button type={"submit"}>登录</button>
      </form>
    </div>
  );
};
